home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 July & August / PCWorld_2007-07-08_cd.bin / komunikace / ie7pro / IE7proSetup.exe / {app} / plugins / accuweather / plugin.js < prev   
Text File  |  2007-04-23  |  9KB  |  224 lines

  1. ∩╗┐// ==UserScript==
  2. // @name          Accu Weather
  3. // @namespace     http://iescripts.org
  4. // @description      Display the local weather in the statusbar, Copy from Windows vista accu weather gadgets
  5. // @statussize    180
  6. // ==/UserScript==
  7.  
  8. (function()
  9. {
  10.   var plugin = PRO_plugin(@name);
  11.   var currentWeather = ""; 
  12.   var currentIcon = "ie7pro://pluginpath/images/01.png";  
  13.   var currentTip = "";
  14.  
  15.   var WeatherUnits;
  16.   var CurrentLocation;
  17.   var CurrentConditions;
  18.   var CurrentImages;
  19.   var CurrentForecasts;
  20.   var CurrentWatches;
  21.   var CurrentLinks;
  22.   var ErrorString="";
  23.   var DataComplete=false;
  24.  
  25.   plugin.registerContextMenu("Set Location", menuSetLocation);
  26.   plugin.ontabcreate = handleTabCreate;
  27.   plugin.onpopupclose = handlePopupClose;
  28.  
  29.   var reqObj = new Object();
  30.   reqObj.request = function(callback, cookie, url, userAgent, lastModify,qtype) {
  31.       var req;
  32.       req = PRO_xmlhttpRequest();
  33.       req.onreadystatechange = function() {
  34.           if (req.readyState == 4) {// completed
  35.               if (req.status < 400) {// only if "OK"
  36.                   try {
  37.                       callback(req, cookie);
  38.                   } catch(err) {
  39.                   }
  40.               } else {
  41.                   // PRO_log("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
  42.               }
  43.               setTimeout(function() {req.forceClean();req = null;}, 1000);
  44.           }
  45.       }
  46.       try {
  47.           req.open(qtype, url);
  48.           req.setRequestHeader( "User-Agent", userAgent);
  49.           if(lastModify.length > 0)
  50.               req.setRequestHeader( "If-Modified-Since", lastModify);
  51.           req.send(null);
  52.  
  53.       } catch(err){ 
  54.       }
  55.       return req;
  56.   }
  57.  
  58.   UpdateWeather();
  59.   setInterval(UpdateWeather, 1000*60*30 );
  60.  
  61.   function menuSetLocation(cookie,url) {
  62.       plugin.popupWindow("ie7pro://pluginpath/findLocation.html",500,400,cookie);
  63.   }
  64.  
  65.   function handleTabCreate(cookie) {
  66.       plugin.setStatusInfo(currentIcon, currentWeather, currentTip);
  67.   }
  68.  
  69.   function handlePopupClose(cookie) {
  70.       UpdateWeather();
  71.   }
  72.  
  73.   function processWeatherData(req, cookie) {
  74.       parseData(req.responseXML.documentElement);
  75.   }
  76.  
  77.   function UpdateWeather() {
  78.       var mylocation=PRO_getValue("weather_Location","10001");
  79.       var mymetric=PRO_getValue("weather_Unit","metric");
  80.       var met = 1;
  81.       if(mymetric == "english")  met = 0;
  82.       var queryurl = "http://vwidget.accuweather.com/widget/vista1/weather_data_v2.asp?location=" + mylocation + "&metric=" + met;
  83.       reqObj.request(processWeatherData, "", queryurl, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; Alexa Toolbar)", "Thu, 26 Aug 2002 08:24:16 GMT","GET");    
  84.   }
  85.  
  86. function Images(xmlNode) {
  87.     this.radar=xmlNode.getElementsByTagName('radar').item(0).firstChild.data;
  88. }
  89.  
  90. function Units(xmlNode) {
  91.     this.tempUnit=xmlNode.getAttribute('temp');
  92.     this.speedUnit=xmlNode.getAttribute('speed');
  93.     this.distUnit=xmlNode.getAttribute('dist');
  94.     this.presUnit=xmlNode.getAttribute('pres');
  95.     this.precUnit=xmlNode.getAttribute('prec');
  96. }
  97.  
  98. function Watches(xmlNode) {
  99.     this.zone=xmlNode.getAttribute('zone');
  100.     this.county=xmlNode.getAttribute('county');
  101.     this.isactive=xmlNode.getAttribute('isactive');
  102.     if (xmlNode.getElementsByTagName('url').item(0).firstChild!=null) {
  103.         this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
  104.     } else {
  105.         this.url="";
  106.     }
  107. }
  108.  
  109. function Location(xmlNode) {
  110.     this.city=xmlNode.getAttribute('city');
  111.     this.state=xmlNode.getAttribute('state');
  112. }
  113.  
  114. function Conditions(xmlNode) {
  115.     this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
  116.     tempNode=xmlNode.getElementsByTagName('wxc').item(0);
  117.     this.temperature=tempNode.getAttribute('temp');
  118.     this.realFeel=tempNode.getAttribute('rft');
  119.     this.humidity=tempNode.getAttribute('hum');
  120.     this.text=tempNode.getAttribute('text');
  121.     this.icon=tempNode.getAttribute('icon');
  122.     this.windGust=tempNode.getAttribute('wgus');
  123.     this.windSpeed=tempNode.getAttribute('wspd');
  124.     this.windDir=tempNode.getAttribute('wdir');
  125.     this.visibility=tempNode.getAttribute('vis');
  126.     this.precip=tempNode.getAttribute('prec');
  127.     this.uvindex=tempNode.getAttribute('uvi');
  128.     this.uvtext=tempNode.getAttribute('uvt');
  129.     this.radarUrl=xmlNode.getElementsByTagName('radurl').item(0).firstChild.data;
  130. }
  131.  
  132. function Links(xmlNode) {
  133.     this.promo1Link=xmlNode.getElementsByTagName('promo1').item(0).getAttribute('url');
  134.     this.promo1Name=xmlNode.getElementsByTagName('promo1').item(0).getAttribute('name');
  135.     this.homeLink=xmlNode.getElementsByTagName('home').item(0).getAttribute('url');    
  136. }
  137.  
  138. function Forecasts(xmlNode) {
  139.     tempNodes=xmlNode.getElementsByTagName('day');
  140.     tempArray=new Array(tempNodes.length);
  141.     for (count=0;count<tempNodes.length;count++) {
  142.         tempArray[count]=new ForecastDay(tempNodes[count]);
  143.     }
  144.     this.forecastArray=tempArray;
  145. }
  146.  
  147. function ForecastDay(xmlNode) {
  148.     this.dayNumber=xmlNode.getAttribute('number');
  149.     this.date=xmlNode.getAttribute('date');
  150.     this.weekDay=xmlNode.getAttribute('wday');
  151.     switch (this.weekDay) {
  152.         case "Monday" : this.shortWeekDay="Mon";break;
  153.         case "Tuesday" : this.shortWeekDay="Tue";break;
  154.         case "Wednesday" : this.shortWeekDay="Wed";break;
  155.         case "Thursday" : this.shortWeekDay="Thu";break;
  156.         case "Friday" : this.shortWeekDay="Fri";break;
  157.         case "Saturday" : this.shortWeekDay="Sat";break;
  158.         case "Sunday" : this.shortWeekDay="Sun";break;
  159.     }
  160.     this.url=xmlNode.getElementsByTagName('url').item(0).firstChild.data;
  161.     
  162.     //Daytime forecast data
  163.     this.daytimeTextShort=xmlNode.getElementsByTagName('./daytime/txtshort').item(0).firstChild.data;
  164.     this.daytimeTextLong=xmlNode.getElementsByTagName('./daytime/txtlong').item(0).firstChild.data;
  165.     this.daytimeIcon=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('icon');
  166.     this.daytimeHigh=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('htmp');
  167.     this.daytimeRealFeelHigh=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('rfh');
  168.     this.daytimeWindSpeed=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wspd');
  169.     this.daytimeWindDirection=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wdir');
  170.     this.daytimeWindGust=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('wgus');
  171.     this.daytimeMaxUV=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('mxuv');
  172.     this.daytimeRain=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('rain');
  173.     this.daytimeSnow=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('snow');
  174.     this.daytimePrecip=xmlNode.getElementsByTagName('./daytime/wxf').item(0).getAttribute('prec');
  175.     
  176.     //Nighttime forecast data
  177.     this.nighttimeTextShort=xmlNode.getElementsByTagName('./nighttime/txtshort').item(0).firstChild.data;
  178.     this.nighttimeTextLong=xmlNode.getElementsByTagName('./nighttime/txtlong').item(0).firstChild.data;
  179.     this.nighttimeIcon=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('icon');
  180.     this.nighttimeLow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('ltmp');
  181.     this.nighttimeRealFeelLow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('rfl');
  182.     this.nighttimeWindSpeed=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wspd');
  183.     this.nighttimeWindDirection=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wdir');
  184.     this.nighttimeWindGust=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('wgus');
  185.     this.nighttimeRain=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('rain');
  186.     this.nighttimeSnow=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('snow');
  187.     this.nighttimePrecip=xmlNode.getElementsByTagName('./nighttime/wxf').item(0).getAttribute('prec');
  188. }
  189.  
  190. function parseData(xmlData) {
  191.     try {
  192.         CurrentLocation=new Location(xmlData.getElementsByTagName("./local").item(0));
  193.         WeatherUnits=new Units(xmlData.getElementsByTagName("./units").item(0));
  194.         CurrentConditions=new Conditions(xmlData.getElementsByTagName("./currentconditions").item(0));
  195.         CurrentImages=new Images(xmlData.getElementsByTagName("./images").item(0));
  196.         CurrentForecasts=new Forecasts(xmlData.getElementsByTagName("./forecast").item(0));
  197.         CurrentWatches=new Watches(xmlData.getElementsByTagName("./watchwarnareas").item(0));
  198.         CurrentLinks=new Links(xmlData.getElementsByTagName("./links").item(0));
  199.         DataComplete=true;
  200.         var mymetric=PRO_getValue("weather_Unit","metric");
  201.         if(mymetric == "metric" ) 
  202.             met = "Γäâ";
  203.         else
  204.             met = "Γäë";
  205.  
  206.         currentWeather = "Now: " + CurrentConditions.text + "," + CurrentConditions.temperature  + met + "(" + CurrentLocation.city + ")"; 
  207.         currentIcon = "ie7pro://pluginpath/images/" + CurrentConditions.icon  + ".png";           
  208.         currentTip = '<B>' + CurrentLocation.city + ' Weather Forecast</B><br>';
  209.         for(i=0;i<5;i++) {
  210.             currentTip += CurrentForecasts.forecastArray[i].date + " " + CurrentForecasts.forecastArray[i].weekDay + " Hi:" + CurrentForecasts.forecastArray[i].daytimeHigh + met + " Lo:" + CurrentForecasts.forecastArray[i].nighttimeLow +met + " " + CurrentForecasts.forecastArray[i].daytimeTextShort + "<br>";
  211.         }     
  212.         currentTip += " ";
  213.         plugin.setStatusInfo(currentIcon, currentWeather,currentTip)
  214.     } catch (e) {
  215.  
  216.     }
  217. }
  218.  
  219. }
  220. )();
  221.  
  222.  
  223.  
  224.